﻿/// <reference path="RequestHandler.js" />
/// <reference path="../HttpRequest.js" />
/// <reference path="../../utilities/Xpcom.js" />
///--------------------------------------------------------------------
/// <file name="ModerationQueueHandler.js">
///   Adds markup buttons to the moderation queue page.
/// </file>
///--------------------------------------------------------------------

NAMFox.ns(function() { with (NAMFox) {

this.ModerationQueueHandler = function() {
};

ModerationQueueHandler.prototype = new RequestHandler();
ModerationQueueHandler.prototype.name = "ModerationQueueHandler";

ModerationQueueHandler.prototype.handleRequestCore = function(request, _$) {
    /// <summary>Handles a request.</summary>
    /// <param name="request" type="HttpRequest">
    ///   The HTTP request which encapsulates the document
    ///   and route data for this request.
    /// </param>
    
    // Checkboxes appear only if the user is a moderator.
    if (_$("input[name=selected_arr\\[\\]]").length > 0) {
        _$("form table:even tr:eq(2) td:last").append(
            '<input' +
            '  name="namfox-mod-queue-invert-checked"' +
            '  type="button"' +
            '  class="btnup"' +
            '  value="Invert Checked" />'
        );
        
        _$("input[name=namfox-mod-queue-invert-checked]").click(
            function() {
                var checkboxes = $FX(this.parentNode.parentNode.parentNode).find(
                    "input[name=selected_arr\\[\\]]"
                );
                
                checkboxes.each(
                    function() {
                        this.checked = !this.checked;
                    }
                );
            }
        );
    }
};

}});